﻿using UnityEngine;
using System.Collections;

public class ToggleChangeHandler : MonoBehaviour {
	
	public UIToggle toggleObject;
	public GameObject[] toggleObjects;
	
	private ToggleSetHandler parentHandler;
	public bool prevValue = false;
	
	void Awake()
	{
		parentHandler = transform.parent.gameObject.GetComponent<ToggleSetHandler>();
		toggleObject = GetComponent<UIToggle>();
	}

	public void OnValueChange()
	{
		if(!prevValue)
		{
			foreach(GameObject obj in toggleObjects)
				obj.SetActive(toggleObject.value);
		
			if(toggleObject.value)
				parentHandler.OnToggleActive(this);
		}
		else
			Application.LoadLevel(1);
		
		prevValue = toggleObject.value;
	}
}
